package com.wstx.mediaserver.util;

import java.util.Arrays;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.Supplier;

/**
 * 哈哈原偷，再偷必究
 */

public class Ayaka {
    //FirstPresentElseThrow 找到对象列表中第一个非空值并返回，全空则抛异常
    public static Object FirstPresentEt(Object... c) throws Exception {
        return Arrays.stream(c)
                .filter(Objects::nonNull)
                .findFirst()
                .orElseThrow(() -> new Exception("全部为空"));
    }

    public static Object FirstPresent(Object defaultV,Object... c) throws Exception {
        return Arrays.stream(c)
                .filter(Objects::nonNull)
                .findFirst()
                .orElse(defaultV);
    }

    public static void main(String[] args) throws Exception {
        System.out.println(FirstPresent(22));

    }
}
